<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "/include/head_common.html">
<title>角色<#if role.id??&&role.id!=''>修改<#else>添加</#if></title>
    <meta name="decorator" content="default"/>
    <#include "/include/tree_view.html">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#name").focus();
            $("#inputForm").validate({
                rules: {
                    name: {remote: "checkName?oldName=" + encodeURIComponent("${role.name!''}")},
                    enname: {remote: "checkEnname?oldEnname=" + encodeURIComponent("${role.enname!''}")}
                },
                messages: {
                    name: {remote: "角色名已存在"},
                    enname: {remote: "英文名已存在"}
                },
                submitHandler: function (form) {
                    var ids = [], nodes = tree.getCheckedNodes(true);
                    for (var i = 0; i < nodes.length; i++) {
                        ids.push(nodes[i].id);
                    }
                    $("#menuIds").val(ids);
                    var ids2 = [], nodes2 = tree2.getCheckedNodes(true);
                    for (var i = 0; i < nodes2.length; i++) {
                        ids2.push(nodes2[i].id);
                    }
                    $("#officeIds").val(ids2);
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

            var setting = {
                check: {enable: true, nocheckInherit: true}, view: {selectedMulti: false},
                data: {simpleData: {enable: true}}, callback: {
                    beforeClick: function (id, node) {
                        tree.checkNode(node, !node.checked, true, true);
                        return false;
                    }
                }
            };

            // 用户-菜单
            var zNodes = [
				<#list menuList as menu>
					{
    					id: "${menu.id}",
    					pId: "<#if menu.parentId??&&menu.parentId!=''>${menu.parentId!''}<#else>0</#if>",
    					name: "<#if menu.parentId??&&menu.parentId!=''>${menu.name}<#else>权限列表</#if>"
					},
				</#list>];
            // 初始化树结构
            var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
            // 不选择父节点
            tree.setting.check.chkboxType = {"Y": "ps", "N": "s"};
            // 默认选择节点
            var ids = "${role.menuIds!''}".split(",");
            for (var i = 0; i < ids.length; i++) {
                var node = tree.getNodeByParam("id", ids[i]);
                try {
                    tree.checkNode(node, true, false);
                } catch (e) {
                }
            }
            // 默认展开全部节点
            tree.expandAll(true);

            // 用户-机构
            var zNodes2 = [
                <#list officeList as office>
                    {
                    	id: "${office.id!''}",
                    	pId: "<#if office.parentId??&&office.parentId!=''>${office.parentId!''}<#else>0</#if>",
                    	name: "${office.name!''}"
                	},
                </#list>];
            // 初始化树结构
            var tree2 = $.fn.zTree.init($("#officeTree"), setting, zNodes2);
            // 不选择父节点
            tree2.setting.check.chkboxType = {"Y": "ps", "N": "s"};
            // 默认选择节点
            var ids2 = "${role.officeIds!''}".split(",");
            for (var i = 0; i < ids2.length; i++) {
                var node = tree2.getNodeByParam("id", ids2[i]);
                try {
                    tree2.checkNode(node, true, false);
                } catch (e) {
                }
            }
            // 默认展开全部节点
            tree2.expandAll(true);
            // 刷新（显示/隐藏）机构
            refreshOfficeTree();
            $("#dataScope").change(function () {
                refreshOfficeTree();
            });
        });
        function refreshOfficeTree() {
            if ($("#dataScope").val() == 9) {
                $("#officeTree").show();
            } else {
                $("#officeTree").hide();
            }
        }
        function goback(){
        	$.cookie('goback','goback',{path: '/',expires: 1});
        	history.go(-1);
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="list">角色列表</a></li>
    <li class="active"><a href="edit?id=${role.id!''}">角色<#if role.id??&&role.id!=''>修改<#else>添加</#if></a></li>
</ul>
<br/>
<#include "/include/message.html">
<form id="inputForm" action="edit" method="post" class="form-horizontal">
    <input type="hidden" name="id" value="${role.id!''}"/>
    <div class="control-group">
        <label class="control-label">归属机构:</label>
        <div class="controls">
            <@wolfking.treeView id="office" name="officeId" 
						value="${office.id!''}" 
						labelName="${office.name!''}"
                        labelValue="${office.name!''}"
                        title="机构" 
                        url="/office/treeData"
                        cssClass="required">
				<#include "/tool/treeTag.html">
			</@wolfking.treeView>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">角色名称:</label>
        <div class="controls">
            <input id="oldName" name="oldName" type="hidden" value="${role.name!''}" />
            <input type="text" name="name" value="${role.name!''}" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">英文名称:</label>
        <div class="controls">
            <input id="oldEnname" name="oldEnname" type="hidden" value="${role.enname!''}" />
            <input type="text" name="enname" value="${role.enname!''}" maxlength="50" class="required"/>
            <span class="help-inline"><font color="red">*</font> 工作流用户组标识</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">角色类型:</label>
        <div class="controls">
            <select name ="roleType" class="input-medium">
                <option value="assignment">任务分配</option>
                <option value="security-role">管理角色</option>
                <option value="user">普通角色</option>
            </select>
            <span class="help-inline"
                  title="activiti有3种预定义的组类型：security-role、assignment、user 如果使用Activiti Explorer，需要security-role才能看到manage页签，需要assignment才能claim任务">
					工作流组用户组类型（任务分配：assignment、管理角色：security-role、普通角色：user）</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">是否系统数据:</label>
        <div class="controls">
            <select name="sysData">
                <option value="0" <#if role.sysData??&&role.sysData='0'> selected </#if>>否</option>
                <option value="1" <#if role.sysData??&&role.sysData='1'> selected </#if>>是</option>
            </select>
            <span class="help-inline">“是”代表此数据只有超级管理员能进行修改，“否”则表示拥有角色修改人员的权限都能进行修改</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">是否可用</label>
        <div class="controls">
            <select name="useable">
                <option value="0" <#if role.useable??&&role.useable='0'> selected </#if>>否</option>
                <option value="1" <#if role.useable??&&role.useable='1'> selected </#if>>是</option>
            </select>
            <span class="help-inline">“是”代表此数据可用，“否”则表示此数据不可用</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">数据范围:</label>
        <div class="controls">
            <select id="dataScope" name="dataScope" class="input-medium" onchange="refreshOfficeTree()">
            	<#list dicts as dict>
            		<option value="${dict.value!''}" <#if role.dataScope??&&role.dataScope=dict.value> selected </#if> >${dict.label!''}</option>
            	</#list>
            </select>
            <span class="help-inline">特殊情况下，设置为“按明细设置”，可进行跨机构授权</span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注:</label>
        <div class="controls">
        	<textarea rows="2" class="input-xlarge" name="remarks">${role.remarks!''}</textarea>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">角色授权:</label>
        <div class="controls">
            <div id="menuTree" class="ztree" style="margin-top:3px;float:left;"></div>
            <input id="menuIds" type="hidden" name="menuIds" value="${role.menuIds!''}"/>
            <div id="officeTree" class="ztree" style="margin-left:100px;margin-top:3px;float:left;"></div>
            <input id="officeIds" type="hidden" name="officeIds" value="${role.officeIds!''}"/>
        </div>
    </div>
    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="goback()"/>
    </div>
</form>
</body>
</html>